package com.orhon.smartcampus.modules.base.mm;

import org.mapstruct.InheritConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

import com.orhon.smartcampus.basicComponents.service.GQLRunService;
import com.orhon.smartcampus.modules.base.entity.Dictionary;
import com.orhon.smartcampus.modules.base.entity.Regions;
import com.orhon.smartcampus.modules.base.gqlModel.GQLDictionary;
import com.orhon.smartcampus.modules.base.gqlModel.GQLRegion;
import com.orhon.smartcampus.utils.ObjectToMap;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;

@Mapper(uses = {
		LangMapper.class
})
public interface RegionMapper {

	RegionMapper MAPPER = Mappers.getMapper(RegionMapper.class);

	@Mapping(source="id", target ="id")
	@Mapping(source = "regionSlug" , target = "slug")
	@Mapping(source = "level",target = "level")
	@Mapping(source = "regionOrder",target = "order")
	@Mapping(source = "createdAt",target = "created_at")
	@Mapping(source = "updatedAt",target = "updated_at")
	@Mapping(source = "deletedAt",target = "deleted_at")
	@Mapping(source = "regionName",target = "name")//lang
	@Mapping(ignore = true, target = "parent" )//父级地区
	GQLRegion toRegions(Regions entity);

	@InheritConfiguration(name = "toRegions")
	List<GQLRegion> toRegionsList(List<Regions> entities);

	@Named("str2reg")
	default GQLRegion fromRegion (Long id){
		HashMap<String,Object> map = GQLRunService.RegionMap();
		Regions object = (Regions) map.get(id+"");
		GQLRegion regions = RegionMapper.MAPPER.toRegions(object);
		return regions;
	}
}
